﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<div class="container-div">
    <div class="row">
        <div id="searchDiv" class="col-sm-12 ">
            <div class="select-list">
                <ul>
                    <li>
                        教师姓名：<input id="teacherName" col="Name" type="text" />
                    </li>
                    <li>
                        <a id="btnSearch" class="btn btn-primary btn-sm" onclick="searchGrid()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                    </li>
                </ul>
            </div>
            
        </div>
        <div class="btn-group-sm " id="toolbar">
            <a id="btnAdd" class="btn btn-success" onclick="showSaveForm(true)"><i class="fa fa-plus"></i> 新增</a>
            <a id="btnEdit" class="btn btn-primary disabled" onclick="showSaveForm(false)"><i class="fa fa-edit"></i> 修改</a>
            <a id="btnDelete" class="btn btn-danger disabled" onclick="deleteForm()"><i class="fa fa-remove"></i> 删除</a>
        </div>
 
        <div class="col-sm-12 select-table table-striped">
            <table id="gridTable" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>

<script type="text/javascript">  
    $(function () {
        initGrid();
    });

    function initGrid() {
        var queryUrl = '@Url.Content("~/TrainingManage/Teacher/GetPageListJson")';

        $('#gridTable').ysTable({
            url: queryUrl,
            columns: [
                { checkbox: true, visible: true },
                { field: 'Id', title: 'Id', visible: false },
                { field: 'Name', title: '教师姓名', sortable: true },
                { field: 'Age', title: '年龄', sortable: true },
                {
                    field: 'Birthday', title: '生日', sortable: true, formatter: function (value, row, index) {
                        return ys.formatDate(value, "yyyy-MM-dd");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="#" onclick="showDetailForm(\'' + row.Id + '\')"><i class="fa fa-key"></i>详细</a>');
                        return actions.join('');
                    }
                }
            ],
            queryParams: function (params) {
                var pagination = $('#gridTable').ysTable('getPagination', params);

                var queryString = $('#searchDiv').getWebControls(pagination);

                return queryString;
            }
        });
    }

    function searchGrid() {
        $('#gridTable').ysTable('search');
        resetToolbarStatus();
    }

    function print() {       
        var postData = $("#searchDiv").getWebControls(); 
        var num = postData.Number;            // var num = $("#txtNumber").val();
        var num2 = postData.Number2;
        var chk222 = postData.Check2;

        console.log(num);
        console.log(num2);
        console.log(chk222);

        if ( num==null )
            alert("请输入箱号/货号。");
        else {
            // 送回DB
            //var postData = $("#form").getWebControls({ Id: id });       

            var  postData = {
                "codeabc": num,
                "nameabc": "abc",
                "ageabc": 18
            };            

            ys.ajax({
                url: '@Url.Content("~/TrainingManage/Teacher/SaveBarJson")',
                type: "post",
                data: postData,
                success: function (obj) {
                    //if (obj.Tag == 1) {
                    //    ys.msgSuccess(obj.Message);
                    //    parent.searchGrid();
                    //    parent.layer.close(index);
                    //}
                    //else {
                    //    ys.msgError(obj.Message);
                    //}
                }
            });


            // 本地打印

        }

    }

    function showSaveForm(bAdd) {
        var id = 0;
        if (!bAdd) {
            var selectedRow = $("#gridTable").bootstrapTable("getSelections");
            if (!ys.checkRowEdit(selectedRow)) {
                return;
            }
            else {
                id = selectedRow[0].Id;
            }
        }
        ys.openDialog({
            title: id > 0 ? "编辑教师信息" : "添加教师信息",
            content: '@Url.Content("~/TrainingManage/Teacher/TeacherForm")' + '?id=' + id,
            width: "768px",
            height: "600px",
            callback: function (index, layero) {
                var iframeWin = window[layero.find('iframe')[0]['name']];
                iframeWin.saveForm(index);
            }
        });
    }

    function deleteForm() {
        var selectedRow = $("#gridTable").bootstrapTable("getSelections");
        if (ys.checkRowDelete(selectedRow)) {
            ys.confirm("确认要删除选中的" + selectedRow.length + "条数据吗？", function () {
                var ids = ys.getIds(selectedRow);
                ys.ajax({
                    url: '@Url.Content("~/TrainingManage/Teacher/DeleteFormJson")' + '?ids=' + ids,
                    type: "post",
                    success: function (obj) {
                        if (obj.Tag == 1) {
                            ys.msgSuccess(obj.Message);
                            searchGrid();
                        }
                        else {
                            ys.msgError(obj.Message);
                        }
                    }
                });
            });
        }
    }

  function showDetailForm(id) {
        ys.openDialog({
            title: "查看教师详细信息",
            content: '@Url.Content("~/TrainingManage/Teacher/TeacherDetail")' + '?id=' + id,
            width: "768px",
            height: "500px"
        });
    }
</script>
